package cn.wolfcode.luowowo.scenic.domain;

import cn.wolfcode.luowowo.common.domain.BaseDomain;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.util.*;

@Setter
@Getter
@ToString
public class ScenicComment extends BaseDomain {
    public static final Integer COMMENT_NOMAL = 0; //普通点评
    public static final Integer COMMENT_GOLD = 1; //金牌点评


    //景点id
    private Long scenicId;
    //景点名字
    private String scenicName;
    //景点图片,只获取第一张
    private String scenicImg;
    //所属目的地
    private Long destId;
    //用户
    private UserInfo user;
    //点评时间
    private Date createTime;
    //点评内容
    private String comment;
    //点评点赞数目
    private Integer thumbupnum = 0;
    //点赞用户
    private List<Long> thumbuplist = new ArrayList<>();

    //点评图片
    private String imgUrls;
    //图片引用数组
    private String[] pictures;
    //总体评价星星
    private int rank = 0;
    //风光星星
    private int sceneRank = 0;
    //特色星星
    private int featureRank = 0;
    //服务星星
    private int serviceRank = 0;
    //子评论
    List<ScenicCommentReply> commentReplies = new ArrayList<>();
    //状态 区分金牌点评以及普通点评
    private int type = COMMENT_NOMAL;
    //评论状态 不良信息的可以禁用掉
    private int state;

    //页面取值时使用
    public String[] getPictures() {
        String[] pics = null;
        if (StringUtils.hasLength(imgUrls)) {
            pics = imgUrls.split(",");
        }
        return pics;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("scenicId", scenicId);
        map.put("scenicName", scenicName);
        if (imgUrls != null) {
            map.put("imgUrls", imgUrls);
        }
        if (pictures != null) {
            map.put("pictures", pictures);
        } else {
            map.put("pictures", getPictures());
        }
        map.put("rank", rank);
        map.put("destId", destId);
        map.put("sceneRank", sceneRank);
        map.put("featureRank", featureRank);
        map.put("serviceRank", serviceRank);
        map.put("comment", comment);

        return JSON.toJSONString(map);
    }
}